import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)
// 静态加载引入
import Login from '@/views/login'
import Layout from '@/layout'

const routes = [


]

// 路由一分为三
// 静态路由
export const constantRouters = [
  // 首页重定向
  {
    path: '/',
    redirect: '/home',
    hidden: true
  },
  // 登录
  {
    path: '/login',
    component: Login,
    hidden: true,
  },
  // 首页
  {
    path: '/home',
    component: Layout, //框架
    meta: { path: '/home', title: '后台首页', icon: 's-home' },
    children: [
      {
        path: '',
        component: () => import('@/views/home')
      }
    ]

  },
]

// 动态路由
export const asyncRouters = [

  // 订单管理
  {
    path: '/order',
    component: Layout,
    meta: { path: '/order', title: '订单管理', roles: ['super'], icon: 'document' },
    children: [
      {
        path: '',
        component: () => import('@/views/order')
      }
    ]
  },
  // 商品管理
  {
    path: '/goods',
    redirect: '/goods/goods-list',
    meta: { path: '/goods', title: '商品管理', icon: 'shopping-bag-1' },
    component: Layout,

    children: [
      {
        // 商品列表
        path: '/goods/goods-list',
        meta: { path: '/goods/goods-list', title: '商品列表' },
        component: () => import('@/views/goods/goods-list.vue')
      },
      {
        // 商品添加
        path: '/goods/goods-add',
        meta: { path: '/goods/goods-add', title: '商品添加', roles: ['super'] },
        component: () => import('@/views/goods/goods-add.vue')
      },
      {
        // 商品分类
        path: '/goods/goods-cate',
        meta: { path: '/goods/goods-cate', title: '商品分类', roles: ['super'] },
        component: () => import('@/views/goods/goods-cate.vue')
      },
    ]

  },
  // 店铺管理
  {
    path: '/shop',
    component: Layout,
    meta: { path: '/shop', title: '店铺管理', roles: ['super'], icon: 'takeaway-box' },
    children: [
      {
        path: '',
        component: () => import('@/views/shop')
      }

    ]
  },
  // 账号管理
  {
    path: '/account',
    redirect: '/account/account-list',
    meta: { path: '/account', title: '账号管理', icon: 'user' },
    component: Layout,
    children: [
      // 账号列表
      {
        path: '/account/account-list',
        meta: { path: '/account/account-list', title: '账号列表', roles: ['super'] },
        component: () => import('@/views/account/account-list.vue')

      },
      // 添加账号
      {
        path: '/account/account-add',
        meta: { path: '/account/account-add', title: '添加账号', roles: ['super'] },
        component: () => import('@/views/account/account-add.vue')
      },
      // 修改密码
      {
        path: '/account/password-modify',
        meta: { path: '/account/password-modify', title: '修改密码' },
        component: () => import('@/views/account/password-modify.vue')
      },
      // 个人中心
      {
        path: '/account/account-person',
        meta: { path: '/account/account-person', title: '个人中心' },
        component: () => import('@/views/account/account-person.vue')
      },

    ]
  },
  // 销售统计
  {
    path: '/total',
    redirect: '/total/total-goods',
    meta: { path: '/total', title: '销售统计', roles: ['super'], icon: 'pie-chart' },
    component: Layout,
    children: [
      // 商品统计
      {
        path: '/total/total-goods',
        meta: { path: '/total/total-goods', title: '商品统计' },
        component: () => import('@/views/total/total-goods.vue')
      },
      // 订单统计
      {
        path: '/total/total-order',
        meta: { path: '/total/total-order', title: '订单统计' },
        component: () => import('@/views/total/total-order.vue')
      }
    ]
  },
]

// 错误路由
export const errorRouters = [
  // 错误路由
  {
    path: '*',
    redirect: '/404'
  },
  {
    path: '/404',
    component: () => import('@/views/404/error.vue')
  }
]

const router = new VueRouter({
  routes: constantRouters
})

// 解决路由原地跳转报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}
export default router
